<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('处理问题')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div>
        <ul>
            <li class="wttw_head">问题提问</li>
        </ul>
    </div>
    <form class="form-horizontal m" id="form-dfQuestion-edit" th:object="${dfQuestion}">
        <input id="id" name="id" th:field="*{id}"  type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">用户名称：</label>
            <div class="col-sm-8">
                <input id="userName" name="userName" th:field="*{userName}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">用户id：</label>
            <div class="col-sm-8">
                <input id="userId" name="userId" th:field="*{userId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">用户单位：</label>
            <div class="col-sm-8">
                <input id="userDept" name="userDept" th:field="*{userDept}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">用户单位id：</label>
            <div class="col-sm-8">
                <input id="userDeptId" name="userDeptId" th:field="*{userDeptId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">联系方式：</label>
            <div class="col-sm-8">
                <input id="userPhone" name="userPhone" th:field="*{userPhone}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">问题处理结果：</label>
            <div class="col-sm-8">
                <input id="questionState" name="questionState" th:field="*{questionState}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题类型：</label>
            <div class="col-sm-8" style="padding-top: 3px;">
                <select name="questionType" class="form-control">
                    <option value="2">处理</option>
                    <option value="3">解释</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题版本号：</label>
            <div class="col-sm-8">
                <select name="questionVersion" class="form-control" th:with="type=${@dict.getType('df_question_version')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题标题：</label>
            <div class="col-sm-8">
                <input id="questionTitle" name="questionTitle" th:field="*{questionTitle}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题描述：</label>
            <div class="col-sm-8">
                <textarea id="questionContent" name="questionContent" th:field="*{questionContent}" class="form-control" type="text"></textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">附件：</label>
            <div class="col-sm-8">
                <ul th:each="file,fileStat : ${dfQuestion.files}" style="padding-left: 0;">
                    <img class="question_imgFile" th:src="${file.fileId}" th:if="${file.fileType=='png'||file.fileType=='jpg'}" data-id="${file.id}">
                    <img th:src="@{/img/tb_word.png}" th:if="${file.fileType=='docx'||file.fileType=='doc'}">
                    <img th:src="@{/img/tb_excel.png}" th:if="${file.fileType=='xls'||file.fileType=='xlsx'}">
                    <img th:src="@{/img/tb_zip.png}" th:if="${file.fileType=='zip'||file.fileType=='rar'}">
                    <img th:src="@{/img/tb_ppt.png}" th:if="${file.fileType=='ppt'||file.fileType=='pptx'}">
                </ul>
            </div>
        </div>
        <div id="outerdiv" style="position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:2;width:100%;height:100%;display:none;">
            <div id="innerdiv" style="position:absolute;">
                <img id="bigimg" style="border:5px solid #fff;" src="" />
            </div>
        </div>

        <div class="form-group" th:each="list:${dfQuestionChild}">
            <ul>
                <li class="wttw_head">问题解决1</li>
            </ul>
            <div style="margin-top: 20px;" th:if="${list.questionType== '2'}">
                <label  class="col-sm-3 control-label">解决方案：</label>
                <div class="col-sm-8">
                    <textarea  th:text="${list.questionInfo}" class="form-control" type="text" readonly></textarea>
                </div>
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <ul th:each="file,fileStat : ${list.files}">
                        <img class="question_imgFile" th:src="${file.fileId}" th:if="${file.fileType=='png'||file.fileType=='jpg'}" data-id="${file.id}">
                        <img th:src="@{/img/tb_word.png}" th:if="${file.fileType=='docx'||file.fileType=='doc'}">
                        <img th:src="@{/img/tb_excel.png}" th:if="${file.fileType=='xls'||file.fileType=='xlsx'}">
                        <img th:src="@{/img/tb_zip.png}" th:if="${file.fileType=='zip'||file.fileType=='rar'}">
                        <img th:src="@{/img/tb_ppt.png}" th:if="${file.fileType=='ppt'||file.fileType=='pptx'}">
                    </ul>
                </div>

            </div>
            <div style="margin-top: 20px;" th:if="${list.questionType== '1'}">
                <label class="col-sm-3 control-label">追加问题描述：</label>
                <div class="col-sm-8">
                    <textarea style="margin-bottom: 20px;"  name="questionInfo"  th:text="${list.questionInfo}" class="form-control" type="text" readonly></textarea>
                </div>

                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <ul th:each="file,fileStat : ${dfQuestion.files}">
                        <img class="question_imgFile" th:src="${file.fileId}" th:if="${file.fileType=='png'||file.fileType=='jpg'}" data-id="${file.id}">
                        <img th:src="@{/img/tb_word.png}" th:if="${file.fileType=='docx'||file.fileType=='doc'}">
                        <img th:src="@{/img/tb_excel.png}" th:if="${file.fileType=='xls'||file.fileType=='xlsx'}">
                        <img th:src="@{/img/tb_zip.png}" th:if="${file.fileType=='zip'||file.fileType=='rar'}">
                        <img th:src="@{/img/tb_ppt.png}" th:if="${file.fileType=='ppt'||file.fileType=='pptx'}">
                    </ul>
                </div>
            </div>
        </div>
    </form>

    <form class="form-horizontal m" id="form-dfQuestion-approve">
        <div class="form-group">
            <div id="approve-div">

                <label class="col-sm-3 control-label">解决方案：</label>
                <div class="col-sm-8">
                    <textarea id="questionAnswer" name="questionInfo"  class="form-control" type="text" placeholder="请输入解决方案"></textarea>
                </div>
                <div >
                    <label class="col-sm-3 control-label">上传附件：</label>
                    <input type="file" accept="image/*" onchange="uploadFile()" id="fileUpload" multiple="multiple" style="display: none"/>
                    <div class="col-sm-8">
                        <ul id="lid"></ul>
                        <ul>
                            <li><button type="button" class="question_addfail"onclick="upload()"></button></li>
                        </ul>

                    </div>
                </div>
                <button style="float: right; margin: 20px 0px 30px 0;"  id="btn_submmit" type="button" class="btn btn-w-m btn-success" onclick="passapprove(questionId);">解决</button>

            </div>
        </div>

    </form>
</div>


<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "question/dfApprove";
    var prefis = ctx + "question/dfFile"
    var preFile = "http://211.149.205.33:18080/file/";
    var id =$("#id").val(); //获取id
    var questionId = $("#id").val();
    $("#form-dfQuestion-edit").validate({
        rules:{
            xxxx:{
                required:true,
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-dfQuestion-edit').serialize());
        }
    }
    //解决问题
    function passapprove(id) {
        $.operate.save(prefix + "/passApprove/"+id, $('#form-dfQuestion-approve').serialize(),addFile);
    }
    function upload() {
        $("#fileUpload").click()
    }

    var arr =[];  //定义一个数组
    function uploadFile(){		 //上传
        var file = $("#fileUpload").get(0).files[0];
        if(file != undefined){
            var formData = new FormData();
            formData.append("files", file);
            $.ajax({
                url:preFile+"mulitiupload",
                type: "POST",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(resp) {
                    var model=new Object();
                    model.fileId =resp[0].fileid; //文件id
                    model.fileName =resp[0].name;//文件名称
                    var index = model.fileName.lastIndexOf(".");
                    var suffix = model.fileName.substring(index+1);
                    model.fileType =suffix; //文件类型
                    arr.push(model);
                    var downUrl="http://211.149.205.33:18080/file/down/"+model.fileId;
                    if(suffix=="png" || suffix=="jpg"){
                        $("#lid").append('<img src="'+preFile+"img/"+model.fileId+'" style="width: 66px;height: 66px" id="img0" >').append(" ");
                    }
                    if(suffix=="xls" || suffix=="xlsx"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001140350+'" style="width: 66px;height: 66px" id="img0"></a>').append(" ");
                    }
                    if(suffix=="docx"|| suffix=="doc"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001206935+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                    }
                    if(suffix=="zip" || suffix=="rar"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001125877+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                    }
                    if(suffix=="ppt" || suffix=="pptx"){
                        $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916091106432+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("附件上传失败。");
                }
            });
        } else {
            $.modal.alertWarning("服务出现错误 。联系管理员 ");
        }
    };
    function addFile(result){
        $.ajax({
           url:prefis+"/editFile",
            type: "POST",
            data: {questionId:result.data,array:JSON.stringify(arr)},
            dataType:"json",
            success: function(resp) {
            }
        });
    }
    //图片处理（放大缩小）
    // var flag = true,//状态true为正常的状态,false为放大的状态
    //     imgH,//图片的高度
    //     imgW,//图片的宽度
    //     img = document.getElementsByTagName('img')[0];//图片元素
    // img.onclick =  function(){
    //     //图片点击事件
    //     imgH = img.height; //获取图片的高度
    //     imgW = img.width; //获取图片的宽度
    //     if(flag){
    //         //图片为正常状态,设置图片宽高为现在宽高的2倍
    //         flag = false;//把状态设为放大状态
    //         img.height = imgH*3;
    //         img.width = imgW*3;
    //     }else{
    //         //图片为放大状态,设置图片宽高为现在宽高的二分之一
    //         flag = true;//把状态设为正常状态
    //         img.height = imgH/3;
    //         img.width = imgW/3;
    //     }
    // }

    //点击图片 在弹出层显示大图
    $(function(){
        $(".pimg").click(function(){
            var _this = $(this);//将当前的pimg元素作为_this传入函数
            imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);
        });
    });
    function imgShow(outerdiv, innerdiv, bigimg, _this){
        var src = _this.attr("src");//获取当前点击的pimg元素中的src属性
        $(bigimg).attr("src", src);//设置#bigimg元素的src属性

        /*获取当前点击图片的真实大小，并显示弹出层及大图*/
        $("<img/>").attr("src", src).load(function(){
            var windowW = $(window).width();//获取当前窗口宽度
            var windowH = $(window).height();//获取当前窗口高度
            var realWidth = this.width;//获取图片真实宽度
            var realHeight = this.height;//获取图片真实高度
            var imgWidth, imgHeight;
            var scale = 0.8;//缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放

            if(realHeight>windowH*scale) {//判断图片高度
                imgHeight = windowH*scale;//如大于窗口高度，图片高度进行缩放
                imgWidth = imgHeight/realHeight*realWidth;//等比例缩放宽度
                if(imgWidth>windowW*scale) {//如宽度扔大于窗口宽度
                    imgWidth = windowW*scale;//再对宽度进行缩放
                }
            } else if(realWidth>windowW*scale) {//如图片高度合适，判断图片宽度
                imgWidth = windowW*scale;//如大于窗口宽度，图片宽度进行缩放
                imgHeight = imgWidth/realWidth*realHeight;//等比例缩放高度
            } else {//如果图片真实高度和宽度都符合要求，高宽不变
                imgWidth = realWidth;
                imgHeight = realHeight;
            }
            $(bigimg).css("width",imgWidth);//以最终的宽度对图片缩放

            var w = (windowW-imgWidth)/2;//计算图片与窗口左边距
            var h = (windowH-imgHeight)/2;//计算图片与窗口上边距
            $(innerdiv).css({"top":h, "left":w});//设置#innerdiv的top和left属性
            $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg
        });

        $(outerdiv).click(function(){//再次点击淡出消失弹出层
            $(this).fadeOut("fast");
        });
    }
    $(".question_imgFile").width($(".col-sm-8").width());
</script>
</body>
</html>
